package schedule.model;

import java.util.ArrayList;

public class Student {

	public String bannerID;
	public ArrayList<inputTime> availableTimes;
	public ArrayList<inputTime> compatibleTimes;
	public milTimeSchedule milTime;
	public milTimeSchedule compatMilTime;
	public booleanSchedule boolTime;
	
	
	public Student(String bannerID){
		this.bannerID = bannerID;		
	}
	//possible place to check if time is already added?
	public void addTime(inputTime newTime){
		availableTimes.add(newTime);
	}
	public void createSchedules(){
		createMyMilTime();		
	}
	//goes through every input time in instance's availableTimes to set according milTime
	private void createMyMilTime(){
		milTimeSchedule mine = new milTimeSchedule();
		//appends hr and min together, as milTimeSchedule expects. i.e. sHr= 10 sMin= 45 turns into 1045
		for (inputTime a: availableTimes){
			StringBuffer sBuffer= new StringBuffer();
			sBuffer.append(a.startHr);
			sBuffer.append(a.startMn);
			int startTime = Integer.parseInt(sBuffer.toString());
			sBuffer.delete(0, sBuffer.length());
			sBuffer.append(a.endHr);
			sBuffer.append(a.endMn);
			int endTime = Integer.parseInt(sBuffer.toString());						
			mine.setAvailable(startTime, endTime);
		}
		milTime = mine;
	}	
	public ArrayList<inputTime> compatInputTime(){
		ArrayList<inputTime> myCompatTimes = new ArrayList<inputTime>();
		int i =0;
		StringBuffer sb = new StringBuffer();
		//convert all available times in compatible milTime back to inputTimes
		while (i<compatMilTime.freeSlot){
			Integer startTime = compatMilTime.getStart(i);
			Integer endTime = compatMilTime.getEnd(i);
			//needed to use StringBuilder to break integer up, e.g. turn 1045 into startHr 10 startMin 45 
			sb.append(startTime.toString());			
			int startHr = Integer.parseInt(sb.substring(0, 1));
			int startMn = Integer.parseInt(sb.substring(2, 3));
			sb.delete(0, sb.length());
			sb.append(endTime.toString());
			int endHr = Integer.parseInt(sb.substring(0, 1));
			int endMn = Integer.parseInt(sb.substring(2, 3));
			//need to take day out of inputTime constructor
			inputTime t = new inputTime(startHr, startMn, endHr, endMn);
			myCompatTimes.add(t);
		}
		return myCompatTimes;
	}
}
